package dimensional.traveler.server.services;

import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.List;

import dimensional.traveler.client.services.MenuImageService;
import dimensional.traveler.shared.Settings;

public class MenuImageServiceImpl implements MenuImageService {

	private final class ImagePathFilter implements FilenameFilter {
		@Override
		public boolean accept(File dir, String fileName) {
			return fileName.endsWith(".jpg") && !fileName.endsWith("placeholder.jpg");
		}
	}

	private static final String MENU_IMAGES_PATH = "images/menu";

	public List<String> getMenuImagePaths() {
		if (Settings.USE_PLACEHOLDERS) {
			return new ArrayList<String>(0);
		} else {
			return getRealMenuImagePaths();
		}
	}

	private List<String> getRealMenuImagePaths() {
		File imagesDirectory = new File(MENU_IMAGES_PATH);
		String[] menuImages = imagesDirectory.list(new ImagePathFilter());
		ArrayList<String> imagePaths = getFullImagePaths(menuImages);
		return imagePaths;
	}

	private ArrayList<String> getFullImagePaths(String[] menuImages) {
		ArrayList<String> imagePaths = new ArrayList<>(menuImages.length);
		for (String imagePath : menuImages) {
			imagePaths.add(MENU_IMAGES_PATH + "/" + imagePath);
		}
		return imagePaths;
	}
}
